package com.example.music.Adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.music.R;
import com.example.music.base.BaseAdapter;
import com.example.music.entity.SongModel;


public class SongAdapter extends BaseAdapter<SongModel, SongAdapter.SongViewHolder>{

    public SongAdapter(Context context) {
        super(context);
    }

    @Override
    protected int onBindLayout() {
        return R.layout.item_list_view;
    }

    @Override
    protected SongAdapter.SongViewHolder onCreateHolder(View view) {
        return new SongViewHolder(view);
    }

    @Override
    protected void onBindData(SongAdapter.SongViewHolder holder, SongModel songModel, int positon) {
        holder.tvSongName.setText(songModel.getName());
        holder.ivSongImage.setTag(songModel.getName());
        if (TextUtils.equals((String) holder.ivSongImage.getTag(), songModel.getName()) && songModel.getPlaying()) {
            holder.ivSongImage.setImageResource(R.drawable.ic_baseline_headset_24);
        } else {
            holder.ivSongImage.setImageResource(R.drawable.ic_baseline_music_note_24);
        }

    }

    public class SongViewHolder extends RecyclerView.ViewHolder {
        ImageView ivSongImage;
        TextView tvSongName;

        public SongViewHolder(@NonNull View itemView) {
            super(itemView);
            ivSongImage = itemView.findViewById(R.id.ivSongImage);
            tvSongName = itemView.findViewById(R.id.tvSongName);
        }

    }
}